<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <script>
  window.onload=function(){
    mydiv = document.getElementById('mydiv');
    mydiv.innerText = "我是用id名访问到的";
    namedivs = document.getElementsByName('namediv');
    len = namedivs.length;
    for(i=0;i<len;i++){
        namedivs[i].innerText='这是用name名访问到的'+i;
    }
    dclass = document.getElementsByClassName('dclass1');
    len = dclass.length;
    for(i=0;i<len;i++){
        dclass[i].innerText='这是用class名访问到的'+i;
    }
    tagDs = document.getElementsByTagName('span');
    len = tagDs.length;
    for(i=0;i<len;i++){
        tagDs[i].innerText='这是用标签名访问到的'+i;
    }
  }

 </script>
 </head>
 <body>
   <div id="mydiv"></div>        <!--用id获取-->
  <hr/>
  <div name="namediv"></div>    <!--用name获取-->
  <div name="namediv"></div>
  <div name="namediv"></div>
  <hr/>
  <div class="dclass1"></div>   <!--用class获取-->
  <div class="dclass1"></div>
  <div class="dclass1"></div>
  <hr/>
  <span></span><br/>            <!--直接用标签名获取-->
  <span></span><br/>
  <span></span><br/>

 </body>
</html>

